package com.zzyl.common.ai;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.core.auth.Auth;
import com.baidubce.qianfan.model.chat.ChatResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AIModelInvoker {

    @Autowired
    private BaiduAIProperties baiduAIProperties;

    //调佣千帆大模型
    public String qianfanInvoker(String prompt) {
        System.out.println(prompt);
        Qianfan qianfan = new Qianfan(Auth.TYPE_OAUTH, baiduAIProperties.getAccessKey(), baiduAIProperties.getSecretKey());
        ChatResponse response = qianfan.chatCompletion()
                .model(baiduAIProperties.getQianfanModel())// 模型名称
                .addMessage("user", prompt)// 用户输入
                .temperature(0.7)// 温度
                .maxOutputTokens(2000)// 最大输出长度
                .responseFormat("json_object")// 返回结果格式
                .execute();// 执行请求
        String result = response.getResult();
        System.out.println(result);

        return result;
    }

}